#使用生成器打印杨辉三角
def tran(n):
    trans = [[1] if i==0 else [1,1] for i in range(n) ]
    for i in range(2,n):
        index = 0
        for j in range(len(trans[i-1])):
            if  j+1<len(trans[i-1]):
                index +=1
                trans[i].insert(index,trans[i-1][j]+trans[i-1][j+1])
    for i in trans:
        yield i
    return "Successful"

def tran1(n):
    s = [1]
    while True:
        yield s
        nexts = []
        sum = 0
        for i in s:
            nexts.append(i+sum)
            sum = i
        nexts.append(s[len(s)-1])
        s = nexts
        if len(s)==n+1:
            return "done"
if __name__ == '__main__':
    # s = tran(10)
    # for i in s:
    #     print(i)
    #方式1
    # s = tran(10)
    # while True:
    #     try:
    #         print(next(s))
    #     except StopIteration as e:
    #         print("%s"%(e.value))
    #         break
    #方式2
    s = tran1(10)
    while True:
        try:
            print(next(s))
        except StopIteration as e:
            print("%s"%(e.value))
            break